1 Imports System.Data.SqlClient
2 Public Class frmSectionRecord
3
4 Public Sub Getdata()
5 Try
6 con = New SqlConnection(cs)
7 con.Open()
8 cmd = New SqlCommand("SELECT RTRIM(ID), RTRIM(SectionName), RTRIM(Class) from Section order by SectionName", con)
9 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
10 dgw.Rows.Clear()
11 While (rdr.Read() = True)
12 dgw.Rows.Add(rdr(0), rdr(1), rdr(2))
13 End While
14 con.Close()
15 Catch ex As Exception
16 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
17 End Try
18 End Sub
19
20 Private Sub dgw_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgw.RowPostPaint
21 Dim strRowNumber As String = (e.RowIndex + 1).ToString()
22 Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
23 If dgw.RowHeadersWidth < Convert.ToInt32((size.Width + 20)) Then
24 dgw.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
25 End If
26 Dim b As Brush = SystemBrushes.ControlText
27 e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
28
29 End Sub
30
31 Private Sub frmCategory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
32 Getdata()
33 End Sub
34
35 Private Sub dgw_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgw.MouseClick
36 Try
37 Dim dr As DataGridViewRow = dgw.SelectedRows(0)
38 If lblSet.Text = "Student Entry" Then
39 Me.Hide()
40 frmStudent.Show()
41 frmStudent.txtSectionID.Text = dr.Cells(0).Value.ToString()
42 frmStudent.txtSection.Text = dr.Cells(1).Value.ToString()
43 frmStudent.txtClass.Text = dr.Cells(2).Value.ToString()
44 Me.lblSet.Text = ""
45 End If
46 If lblSet.Text = "Class Transfer" Then
47 Me.Hide()
48 frmClassTransfer.Show()
49 frmClassTransfer.txtSectionID.Text = dr.Cells(0).Value.ToString()
50 frmClassTransfer.txtSection.Text = dr.Cells(1).Value.ToString()
51 frmClassTransfer.txtClass.Text = dr.Cells(2).Value.ToString()
52 Me.lblSet.Text = ""
53 End If
54 Catch ex As Exception
55 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
56 End Try
57 End Sub
58
59 Private Sub txtSearchByCategory_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtSearchBySection.TextChanged
60 Try
61 con = New SqlConnection(cs)
62 con.Open()
63 cmd = New SqlCommand("SELECT RTRIM(ID), RTRIM(SectionName), RTRIM(Class) from Section where SectionName like '" & txtSearchBySection.Text & "%' order by SectionName", con)
64 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
65 dgw.Rows.Clear()
66 While (rdr.Read() = True)
67 dgw.Rows.Add(rdr(0), rdr(1), rdr(2))
68 End While
69 con.Close()
70 Catch ex As Exception
71 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
72 End Try
73 End Sub
74
75
76 Private Sub txtSearchByClass_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtSearchByClass.TextChanged
77 Try
78 con = New SqlConnection(cs)
79 con.Open()
80 cmd = New SqlCommand("SELECT RTRIM(ID), RTRIM(SectionName), RTRIM(Class) from Section where Class like '" & txtSearchByClass.Text & "%' order by SectionName", con)
81 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
82 dgw.Rows.Clear()
83 While (rdr.Read() = True)
84 dgw.Rows.Add(rdr(0), rdr(1), rdr(2))
85 End While
86 con.Close()
87 Catch ex As Exception
88 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
89 End Try
90 End Sub
91
92 Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
93 Me.Close()
94 End Sub
95 Sub Reset()
96 txtSearchByClass.Text = ""
97 txtSearchBySection.Text = ""
98 Getdata()
99 End Sub
100 Private Sub btnReset_Click(sender As System.Object, e As System.EventArgs) Handles btnReset.Click
101 Reset()
102 End Sub
103 End Class